package com.dimples.common.util;

import com.dimples.common.entity.SecurityUser;
import com.dimples.common.service.DimplesJwtTokenServiceImpl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;

/**
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2021/6/26
 */
public class SecurityContextUtil {

    /**
     * 刷新缓存
     *
     * @param securityUser SecurityUser
     */
    public static void refreshCache(DimplesJwtTokenServiceImpl tokenService, SecurityUser securityUser) {
        SecurityUser cacheUser = tokenService.getLoginUserFromToken(HttpContextUtil.getRequest());
        securityUser.setLoginDetails(null);
        BeanUtil.copyProperties(securityUser, cacheUser, CopyOptions.create().ignoreNullValue());

        tokenService.validateToken(cacheUser);
    }
}
